import { request } from 'umi';
import type {OweLogItem} from "@/pages/m/OweLogs/data";
import type {LendLogItem} from "@/pages/m/LendLogs/data";

export async function queryOweLog(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: Record<string, any>,
) {
  return request<{
    data: OweLogItem[];
    total: number;
    success?: boolean;
    status?: string;
    message: string;
  }>('/api/oweLog', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {})
  });
}

// 根据oweLogId查询还款记录
export async function queryOwePayBackLog(
  params: {
    oweId: any
  },
  options?: Record<string, any>,
) {
  return request<{
    data: LendLogItem[];
    total?: number;
    success?: boolean;
    status?: string;
  }>('/api/oweLog/paybackLog', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {})
  });
}

// 还钱给别人
export async function updateOwePaybackLog(data: Record<string, any>, options?: Record<string, any>) {
  return request('/api/oweLog/paybackLog', {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

// 更新流水
export async function updateOweLog(data: Record<string, any>, options?: Record<string, any>) {
  return request('/api/oweLog', {
    data,
    method: 'PUT',
    ...(options || {}),
  });
}

// 删除借入流水
export async function deleteOweLog(data: { key: number }, options?: Record<string, any>) {
  return request<Record<string, any>>('/api/oweLog', {
    data,
    method: 'DELETE',
    ...(options || {}),
  });
}

// 从借钱流水中删除还钱记录
export async function deleteOwePaybackLog(data: { key: number, oweId: number }, options?: Record<string, any>) {
  return request<Record<string, any>>('/api/oweLog/paybackLog', {
    data,
    method: 'DELETE',
    ...(options || {}),
  });
}
